package com.zx._03_并发.chapter_00_lock;

import cn.hutool.core.util.ReflectUtil;
import java.util.concurrent.locks.ReentrantLock;

public class AQS观察 {

    public static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) throws Exception {

        info();

        for (int i = 0; i < 10; i++) {
            int finalI = i;
            new Thread(() -> {
                System.out.println("begin=" + finalI);
                lock.lock();
                try {
                    info();
                    int a = 1;
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }).start();
        }
    }

    public static void info() {
        Object sync = ReflectUtil.getFieldValue(lock, "sync");
        Object head = ReflectUtil.getFieldValue(sync, "head");
    }
}
